package com.qyhl.module_practice.center.level;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeLevelBean;

import java.util.List;

public class PracticeLevelModel implements PracticeLevelContract.PracticeLevelModel {
    private PracticeLevelPresenter mPresenter;

    PracticeLevelModel(PracticeLevelPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getLevel() {

        EasyHttp.get(PracticeUrl.GET_PRACTICE_LEVEL_RULE)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<List<PracticeLevelBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！");
                        } else {
                            mPresenter.setError("获取失败，请重新尝试！");
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeLevelBean> practiceLevelBeans) {
                        mPresenter.setLevel(practiceLevelBeans);
                    }
                });

    }
}
